package com.lizhi.yun.core.handler;

import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.jlc.dao.JlcPatinentInfoDao;
import com.lizhi.yun.db.jlc.pojo.JlcPatientInfoPOJO;
import com.lizhi.mybatis.interceptor.PageBounds;
import com.lizhi.utils.StringUtils;
import com.lizhi.yun.deploy.NewBaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: lizhi
 * @Description:
 * @Date: create in 2020/10/27 14:56
 */
@Slf4j
@Service
public class ServiceJlcPatientInfoHandlerNew extends NewBaseHandler {

    @Resource
    private JlcPatinentInfoDao jlcPatinentInfoDao;

    /**
     * 分页查询
     * @param json
     * @return
     */
    public ListResponseResult doMain(String json){
        log.info("获取到的数据是json:{}", json);
        Map<String, Object> map = SamJsonUtil.toMap(json);
        PageBounds pageBounds = getPageBounds(map);
        List<JlcPatientInfoPOJO> list = jlcPatinentInfoDao.selectByMap(map, pageBounds);
        return getListResult(pageBounds.getCountRows(), list, map);
    }

    public ListResponseResult doMain(Map<String, Object> map){
        log.info("获取到的数据是map:{}", map);
        PageBounds pageBounds = getPageBounds(map);
        List<JlcPatientInfoPOJO> list = jlcPatinentInfoDao.selectByMap(map, pageBounds);
        return getListResult(pageBounds.getCountRows(), list, map);
    }

    /**
     * 根据id查询信息
     * @param id
     * @param hospitalid
     * @param hospitalsystemid
     * @return
     */
    public ListResponseResult selectById(String id, String hospitalid, String hospitalsystemid){
        JlcPatientInfoPOJO jlcPatientInfoPOJO = jlcPatinentInfoDao.selectById(id, hospitalid, hospitalsystemid);
        if (StringUtils.isEmpty(jlcPatientInfoPOJO)){
            return getListResult("未查询到患者信息", false);
        }
        return getListResult(jlcPatientInfoPOJO);
    }
}
